package logic

import (
	"context"
	"strconv"
	"strings"

	"mall/service/recommended/api/internal/svc"
	"mall/service/recommended/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetRecommendItemByCategoryLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// todo: 目前无法使用
func NewGetRecommendItemByCategoryLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRecommendItemByCategoryLogic {
	return &GetRecommendItemByCategoryLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetRecommendItemByCategoryLogic) GetRecommendItemByCategory(req *types.ItemSearchReq) (
	resp *types.RecommendItemResp, err error,
) {
	if len(strings.TrimSpace(req.UserId)) == 0 {
		return &types.RecommendItemResp{}, nil
	}

	pageSize, err := strconv.ParseInt(req.PageSize, 10, 64)
	if err != nil {
		logx.Errorf("GetItemNeighbors pageSize ParseInt Error: %+v", err)
		return nil, err
	}
	offset, err := strconv.ParseInt(req.Offset, 10, 64)
	if err != nil {
		logx.Errorf("GetItemNeighbors offset ParseInt Error: %+v", err)
		return nil, err
	}

	res, err := l.svcCtx.GorseClient.GetItemRecommend(l.ctx, req.UserId,
		[]string{"1"}, "like", "",
		int(pageSize), int(offset),
	)
	if err != nil {
		return nil, err
	}

	return &types.RecommendItemResp{
		Ids: res,
	}, nil
}
